import axios from "axios";
export default {
  loadContent({ commit }, { filename }) {
    axios
      .get("./data/" + filename)
      .then(response => {
        commit("SET_CONTENT", response.data);
        commit("SET_TITLE", response.data.title);
      })
      .catch(error => {
        console.log(error);
      });
  },
  loadBrief({ commit }) {
    axios
      .get("./data/list.json")
      .then(response => {
        commit("SET_BRIEF", response.data);
      })
      .catch(error => {
        console.log(error);
      });
  },
  saveData({ state, commit }, { value, details }) {
    commit("SET_CURRENT_SCORES", value);
    commit("SET_CURRENT_DETAILS", details);
    let postData = {
      title: state.content.title,
      header: state.current.header,
      result: state.current.scores,
      detail: state.current.details
    };
    axios
      .post("./api/save/", postData)
      .then(response => {
        console.log(response.data);
      })
      .catch(error => {
        console.log(error);
      });
  },
  queryStorage({ commit }, { range, title }) {
    axios
      .post("./api/query/", { range, title })
      .then(response => {
        commit("SET_STORAGE", response.data);
      })
      .catch(error => {
        console.log(error);
      });
  }
};
